package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"hm-zero-mall/apps/api/api/internal/config"
	"hm-zero-mall/apps/api/api/internal/middleware"
	"hm-zero-mall/apps/user/rpc/user"
)

type ServiceContext struct {
	Config              config.Config
	Redis               *redis.Redis
	TokenAuthMiddleware rest.Middleware
	UserRPC             user.User
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:              c,
		Redis:               redis.New(c.Redis.Host, redis.WithPass(c.Redis.Pass)),
		TokenAuthMiddleware: middleware.NewTokenAuthMiddleware().Handle,
		UserRPC:             user.NewUser(zrpc.MustNewClient(c.UserRPC)),
	}
}
